package com.example.tms.mapper;

import com.example.tms.bean.OrderMgmt;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface OrderMapper extends JpaRepository<OrderMgmt,String>, JpaSpecificationExecutor<OrderMgmt> {

    //查询订单信息（ 订单id）
    @Query(value = "select * from order_mgmt where ddid = ?1 and sfcz = true", nativeQuery = true)
    OrderMgmt findByDdid(String ddid);

    //删除订单信息（假删除 订单id）
    @Query(value = "update order_mgmt set sfcz = false where ddid = ?1", nativeQuery = true)
    @Modifying
    @Transactional
    void DeleteByDdid(String ddid);

    //发布订单（订单id）
    @Query(value = "update order_mgmt set ddzt = '已发布' where ddid = ?1", nativeQuery = true)
    @Modifying
    @Transactional
    void IssueByDdid(String ddid);

    //查询订单信息（订单日期 是否生成订单）
    List<OrderMgmt> findByDdrqAndSfscdd(String ddrq, boolean sfscdd);

    //查询当天订单数（订单日期）
    Long countByDdrq(String ddrq);

    OrderMgmt findByDdhAndSfcz(String ddh, boolean sfcz);

    //更新订单
    @Query(value = "update order_mgmt set huowu = ?2,hwsl=?3,ydj=?4,yunfei=?5,gls=?6 where ddid = ?1", nativeQuery = true)
    @Modifying
    @Transactional
    void UpdateByDdid(String ddid ,String huowu,String hwsl,String ydj,String yunfei,String gls);

    OrderMgmt findByDdidAndSfcz(String ddid, boolean sfcz);
}
